﻿<TargetsRoot xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <DefaultExclude Include="**\.svn\**" />
    <DefaultExclude Include="**\bin\**" />
    <DefaultExclude Include="**\obj\**" />
    <DefaultExclude Include="**\Release\**" />
    <DefaultExclude Include="**\Debug\**" />
    <DefaultExclude Include="**\Test\**" />
    <DefaultExclude Include="**\TestResults\**" />
    <DefaultExclude Include="**\doc\**" />
    <DefaultExclude Include="**\www\**" />
    <DefaultExclude Include="**\*.user" />
    <DefaultExclude Include="**\*.suo" />
    <DefaultExclude Include="**\*.zip" />
    <DefaultExclude Include="**\*.txt" />
  </ItemGroup>

  <ItemGroup>
    <ZipFiles Include="**\*.*" Exclude="@(DefaultExclude)" />
  </ItemGroup>


  <ItemGroup>
    <tablesqlfiles Include="$(DbTablesSqlDirectory)\*.sql" />
  </ItemGroup>
  <ItemGroup>
    <viewssqlfiles Include="$(DbViewsSqlDirectory)\*.sql" />
  </ItemGroup>
  <ItemGroup>
    <procssqlfiles Include="$(DbStoredProcsSqlDirectory)\*.sql" />
  </ItemGroup>


  <ItemGroup>
    <AssemblyInfoFiles Include="$(BuildSourceDirectory)\**\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <AssemblyInfoFilesVB Include="$(BuildSourceDirectory)\**\AssemblyInfo.vb" />
  </ItemGroup>

  <ItemGroup>
    <SettingsFiles Include="$(BuildSettingsDirectory)\*.fxcop" />
    <SettingsFiles Include="$(BuildSettingsDirectory)\*.shfb" />
    <SettingsFiles Include="$(BuildSettingsDirectory)\*.xml" />
  </ItemGroup>

  <ItemGroup>
    <libfiles Include="$(BuildSourceDirectory)\**\*.dll" />
    <libfiles Include="$(BuildSourceDirectory)\**\*.exe" />
  </ItemGroup>


  <!--
      This task will do the pre-requisites done
      to start off with the build script.
  -->
  <Target Name="PreScript">
    <Message Text="Excecuting PreScript Tasks......." />
    <Exec Command="$(BuildSettingsDirectory)\$(PreScriptFile)" />
  </Target>


  <!--
      This task is the startup task for the build process
  -->
  <Target Name="StartUp">
    <CallTarget Targets="UpdateSettings" />

    <Time Format="dd-MM-yyyy HH.mm.ss">
      <Output TaskParameter="FormattedTime" PropertyName="BuildDateTime" />
    </Time>
    <Message Text="Current build date time : $(BuildDateTime)" />
    <MakeDir Directories="$(BuildDirectory)\$(BuildConfiguration)\$(BuildDateTime)" />
    <MakeDir Directories="$(BuildLogsDirectory)\$(BuildConfiguration)\$(BuildDateTime)" />
    <MakeDir Directories="$(BuildDirectory)\Latest" />
    <RemoveDir Directories="$(BuildLogsDirectory)\Latest"></RemoveDir>
    <MakeDir Directories="$(BuildLogsDirectory)\Latest" />
  </Target>

  <!--
      This task will correct all settings file contents to point
      to the right locations and assemblies.
  -->
  <Target Name="UpdateSettings">
    <Message Text="Settings files found are...%(SettingsFiles.Identity)" />
    <FileUpdate Files="%(SettingsFiles.Identity)"
                Regex="/bin/Debug"
                ReplacementText="/bin/Latest"
		Condition=" '%(SettingsFiles.Identity)' != '' ">
    </FileUpdate>
    <FileUpdate Files="%(SettingsFiles.Identity)"
                Regex="/bin/Release"
                ReplacementText="/bin/Latest"
		Condition=" '%(SettingsFiles.Identity)' != '' ">
    </FileUpdate>
    <FileUpdate Files="%(SettingsFiles.Identity)"
                Regex="/bin/$(BuildConfiguration)"
                ReplacementText="/bin/Latest"
		Condition=" '%(SettingsFiles.Identity)' != '' ">
    </FileUpdate>
    <FileUpdate Files="%(SettingsFiles.Identity)"
                Regex="\\bin\\Debug"
                ReplacementText="\bin\Latest"
		Condition=" '%(SettingsFiles.Identity)' != '' ">
    </FileUpdate>
    <FileUpdate Files="%(SettingsFiles.Identity)"
                Regex="\\bin\\Release"
                ReplacementText="\bin\Latest"
		Condition=" '%(SettingsFiles.Identity)' != '' ">
    </FileUpdate>
    <FileUpdate Files="%(SettingsFiles.Identity)"
                Regex="\\bin\\$(BuildConfiguration)"
                ReplacementText="\bin\Latest"
		Condition=" '%(SettingsFiles.Identity)' != '' ">
    </FileUpdate>
    <FileUpdate Files="%(SettingsFiles.Identity)"
                Regex="C:\\Buildroot\\NDependOut"
                ReplacementText="$(BuildRoot)\buildlogs\Latest\NDependOut"
		Condition=" '%(SettingsFiles.Identity)' != '' ">
    </FileUpdate>
    <FileUpdate Files="%(SettingsFiles.Identity)"
                Regex="&lt;OutputPath&gt;.*&lt;/OutputPath&gt;"
                ReplacementText="&lt;OutputPath&gt;$(BuildRoot)\buildlogs\Latest\doc\&lt;/OutputPath&gt;"
		Condition=" '%(SettingsFiles.Identity)' != '' ">
    </FileUpdate>
  </Target>


  <!--
      This task will create the necessary AssemblyInfo.cs files
  -->
  <Target Name="Version">
    <Exec Command="$(BuildSettingsDirectory)\VersionIncrement.exe" ContinueOnError="true"/>
    <Message Text="AssemblyInfo.cs files found are...%(AssemblyInfoFiles.Identity)" />
    <Message Text="Setting Version: $(Major).$(Minor).$(Build).$(Revision)"/>
    <FileUpdate Files="%(AssemblyInfoFiles.Identity)"
                Regex="(\d+)\.(\d+)\.(\d+)\.(\d+)"
                ReplacementText="$(Major).$(Minor).$(Build).$(Revision)"
		Condition=" '%(AssemblyInfoFiles.Identity)' != '' ">
    </FileUpdate>
    <Message Text="AssemblyInfo.vb files found are...%(AssemblyInfoFilesVB.Identity)" />
    <Message Text="Setting Version: $(Major).$(Minor).$(Build).$(Revision)"/>
    <FileUpdate Files="%(AssemblyInfoFilesVB.Identity)"
                Regex="(\d+)\.(\d+)\.(\d+)\.(\d+)"
                ReplacementText="$(Major).$(Minor).$(Build).$(Revision)"
		Condition=" '%(AssemblyInfoFilesVB.Identity)' != '' ">
    </FileUpdate>
  </Target>


  <!--
      This task will do an svn cleanup in the update directory
  -->
  <Target Name="SvnCleanup">
    <Exec Command="$(SvnExePath) cleanup $(DOUBLE_QUOTES)$(SvnUpdateDirectory)$(DOUBLE_QUOTES) --username $(SvnUserName) --password $(SvnPassword)"/>
  </Target>


  <!--
      This task will get the latest code from trunk uri 
  -->
  <Target Name="CodeSvnGet">
    <Exec Command="$(SvnExePath) checkout $(SvnUri) $(DOUBLE_QUOTES)$(SvnUpdateDirectory)$(DOUBLE_QUOTES) --username $(SvnUserName) --password $(SvnPassword)"/>
  </Target>


  <!--
      This task will clean up all the files genera-
      ted by the previously ran <UnitTest> task.
  -->
  <Target Name="CleanStyleCopFiles">
    <Delete Files="$(BuildLogsDirectory)\Latest\$(StyleCopReportFile)" ContinueOnError="true" Condition=" '$(StyleCopReportFile)' != '' " />
  </Target>


  <!--
      This task will run the stylecop for all the *.cs 
      files present in the working directory to ensure 
      that code violations does not occur.
  -->
  <UsingTask AssemblyFile="$(StyleCopTaskAssembly)" TaskName="StyleCopTask"/>
  <Target Name="StyleCop">
    <CreateItem
			Include="$(BuildSourceDirectory)\**\*.cs">

      <Output TaskParameter="Include" ItemName="SourceAnalysisFiles" />
    </CreateItem>

    <Message Text="Scanning Files using Stylecop............."></Message>
    <StyleCopTask
        ProjectFullPath="$(MSBuildProjectFile)"
        
        SourceFiles="@(SourceAnalysisFiles)"
        ForceFullAnalysis="true"
        TreatErrorsAsWarnings="false"
        CacheResults="false"
        OverrideSettingsFile="$(BuildSettingsDirectory)\$(StyleCopCustomSettingsFile)"
        ContinueOnError="true"
        />
    <Copy SourceFiles="$(BuildRoot)\$(StyleCopReportFile)" DestinationFiles="$(BuildLogsDirectory)\$(BuildConfiguration)\$(BuildDateTime)\$(StyleCopReportFile)" ContinueOnError="true" />
    <Copy SourceFiles="$(BuildRoot)\$(StyleCopReportFile)" DestinationFiles="$(BuildLogsDirectory)\Latest\$(StyleCopReportFile)" ContinueOnError="true" />
    <Delete Files="$(BuildRoot)\$(StyleCopReportFile)" ContinueOnError="true" Condition=" '$(StyleCopReportFile)' != '' " />
  </Target>


  <!--
      This task will clean up all the previously built
      files with the same configuration specified.
  -->
  <Target Name="Clean">
    <CreateItem
      Include=
      "
        $(BuildDirectory)\Latest\*.*
      "
      >
      <Output TaskParameter="Include" ItemName="OldBuildFiles"/>
    </CreateItem>
    <Message Text="Cleaning up the previous build files...." />
    <Delete Files="@(OldBuildFiles)" ContinueOnError="true" Condition=" '@(OldBuildFiles)' != '' " />
  </Target>


  <!--
      This task will build the main solution file 
      with the configuration specified.
  -->
  <Target Name="Compile">
    <Message Text="Compiling........" />
    <Message Text="Solution files are...." />
    <Message Text="$(BuildSourceDirectory)\$(MainSolutionFile)" />
    <MSBuild Projects="$(BuildSourceDirectory)\$(MainSolutionFile)"
             Properties="Configuration=$(BuildConfiguration)"  />

    <Message Text="Compiling *.vdproj's........" />
    <CreateItem
			Include="$(BuildSourceDirectory)\**\*.vdproj">
      <Output TaskParameter="Include" ItemName="VdProjFiles" />
    </CreateItem>
    <Message Text="Vdproj files found are...." />
    <Message Text="%(VdProjFiles.Identity)" />
    <Exec Command="$(DOUBLE_QUOTES)$(DevEnvPath)\devenv.com$(DOUBLE_QUOTES) $(BuildSourceDirectory)\$(MainSolutionFile) /project %(VdProjFiles.Identity) /build $(BuildConfiguration)" Condition=" '@(VdProjFiles)' != '' " />   
    <Message Text="Compilation complete............" />
    <CreateItem Include="$(BuildDirectory)\$(BuildConfiguration)\*.*">
      <Output TaskParameter="Include" ItemName="CurrentBuildFiles"/>
    </CreateItem>
	  <CreateItem Include="$(BuildDirectory)\Latest\*.*">
		  <Output TaskParameter="Include" ItemName="CurrentBuildFiles1"/>
	  </CreateItem>
    <Copy SourceFiles="@(CurrentBuildFiles)" DestinationFolder="$(BuildDirectory)\Latest" />
    
    <!--> Clean Up and set base work for MS code coverage process   -->
    <RemoveDir Directories="$(BuildDirectory)\MSCodeCovDir"></RemoveDir>
    <MakeDir Directories="$(BuildDirectory)\MSCodeCovDir"></MakeDir>
    <Copy SourceFiles="$(BuildSettingsDirectory)\mscodecov.bat" DestinationFiles="$(BuildDirectory)\MSCodeCovDir\mscodecov.bat" ContinueOnError="true" />
    <Copy SourceFiles="@(CurrentBuildFiles)" DestinationFolder="$(BuildDirectory)\MSCodeCovDir" />
    <Copy SourceFiles="@(CurrentBuildFiles1)" DestinationFolder="$(BuildDirectory)\MSCodeCovDir" />
    <!--> Done  -->
    
    
    
    <Copy SourceFiles="@(CurrentBuildFiles)" DestinationFolder="$(BuildDirectory)\$(BuildConfiguration)\$(BuildDateTime)" />
    <Copy SourceFiles="@(CurrentBuildFiles1)" DestinationFolder="$(BuildDirectory)\$(BuildConfiguration)\$(BuildDateTime)" />
    <Delete Files="@(CurrentBuildFiles)" ContinueOnError="true" Condition=" '@(CurrentBuildFiles)' != '' " />
  </Target>


  <!--
      This task will build all the solution files 
      under the source folder with the configurations 
      specified.
  -->
  
	<Target Name="PostCompile">
		<Message Text="Post Compile File is running...." />
		<Exec Command="$(BuildSettingsDirectory)\$(PostCompileFile)" />
	</Target>

	<Target Name="PostDeploy">
		<Message Text="Post Deploy File is running...." />
		<Exec Command="$(BuildSettingsDirectory)\$(PostDeployFile)" />
	</Target>


  <!--
      This task will clean up all the files genera-
      ted by the previously ran <UnitTest> task.
  -->
  <Target Name="CleanUpTestFiles">
    <Delete Files="$(BuildLogsDirectory)\Latest\$(NUnitReportFile)" ContinueOnError="true" Condition=" '$(NUnitReportFile)' != '' " />
  </Target>


  <!--
      This task will do the unit testing. Input to
      this task is the Test assembly.
  -->
  <Target Name="UnitTest">  
    <NUnit Assemblies="$(BuildDirectory)\Latest\$(NUnitDLLName)"
            ToolPath="$(NUnitInstallDirectory)"
            WorkingDirectory="$(BuildSourceDirectory)"
            OutputXmlFile="$(BuildLogsDirectory)\$(BuildConfiguration)\$(BuildDateTime)\$(NUnitReportFile)"
            ContinueOnError="true">
      <Output TaskParameter="ExitCode" ItemName="NUnitExitCodes"/>
    </NUnit>
    <Copy SourceFiles="$(BuildLogsDirectory)\$(BuildConfiguration)\$(BuildDateTime)\$(NUnitReportFile)" DestinationFiles="$(BuildLogsDirectory)\Latest\$(NUnitReportFile)" ContinueOnError="true" />
  </Target>


  <!--
      This task will clean up all the files genera-
      ted by the previously ran <Coverage> task.
  -->
  <Target Name="CleanUpCoverageFiles">
    <Message Text="Cleaning up old code coverage results......." />
    <Delete Files="$(BuildLogsDirectory)\Latest\$(CoverageReportFile)" ContinueOnError="true" Condition=" '$(CoverageReportFile)' != '' " />
    <Delete Files="$(BuildLogsDirectory)\Latest\$(CoverageLogFile)" ContinueOnError="true" Condition=" '$(CoverageLogFile)' != '' " />
  </Target>


  <!--
      This task will do the code coverage. Input 
      to this task is the Test assembly and the 
      profiler.
  -->
  <Target Name="Coverage">

    <Message Text="Executing command.....$(NCoverExe) //w $(DOUBLE_QUOTES)$(BuildDirectory)\$(BuildConfiguration)\$(BuildDateTime)$(DOUBLE_QUOTES) //reg //l $(DOUBLE_QUOTES)$(BuildLogsDirectory)\$(BuildConfiguration)\$(BuildDateTime)\$(CoverageLogFile)$(DOUBLE_QUOTES) //h $(DOUBLE_QUOTES)$(BuildLogsDirectory)\$(BuildConfiguration)\$(BuildDateTime)$(DOUBLE_QUOTES) $(AppToProfileExe) $(DOUBLE_QUOTES)@(TestAssemblies)$(DOUBLE_QUOTES)" />

    <Exec Command="$(NCoverExe) //x $(DOUBLE_QUOTES)$(BuildLogsDirectory)\Latest\$(CoverageReportFile)$(DOUBLE_QUOTES) $(AppToProfileExe) $(DOUBLE_QUOTES)$(BuildDirectory)\Latest\$(NUnitDLLName)$(DOUBLE_QUOTES)"/>

    <Copy SourceFiles="$(BuildRoot)\$(CoverageReportFile)" DestinationFiles="$(BuildLogsDirectory)\$(BuildConfiguration)\$(BuildDateTime)\$(CoverageReportFile)" ContinueOnError="true" />
    <Copy SourceFiles="$(BuildRoot)\$(CoverageReportFile)" DestinationFiles="$(BuildLogsDirectory)\Latest\$(CoverageReportFile)" ContinueOnError="true" />
    <Delete Files="$(BuildRoot)\$(CoverageReportFile)" ContinueOnError="true" Condition=" '$(CoverageReportFile)' != '' " />
  </Target>


  <!--
      This task will clean up all the files genera-
      ted by the previously ran <Reporting> task.
  -->
  <Target Name="CleanUpFxcopFiles">
    <Delete Files="$(BuildLogsDirectory)\Latest\$(FxCopResultsFile)" ContinueOnError="true" Condition=" '$(FxCopResultsFile)' != '' " />
  </Target>


  <!--
      This task will do the code quality check usi-
      ng a tool called FxCop.
  -->
  <Target Name="Reporting">
    <Message Text="Executing........FxCopCmd.exe /project:$(BuildSettingsDirectory)\$(FxCopProjectFile) /out:$(BuildLogsDirectory)\$(BuildConfiguration)\$(BuildDateTime)\$(FxCopResultsFile)" />
    <Exec Command="FxCopCmd.exe /project:$(DOUBLE_QUOTES)$(BuildSettingsDirectory)\$(FxCopProjectFile)$(DOUBLE_QUOTES) /out:$(DOUBLE_QUOTES)$(BuildLogsDirectory)\$(BuildConfiguration)\$(BuildDateTime)\$(FxCopResultsFile)$(DOUBLE_QUOTES)" WorkingDirectory="$(FxCopInstallDirectory)" ContinueOnError="true" />
    <Copy SourceFiles="$(BuildLogsDirectory)\$(BuildConfiguration)\$(BuildDateTime)\$(FxCopResultsFile)" DestinationFiles="$(BuildLogsDirectory)\Latest\$(FxCopResultsFile)" ContinueOnError="true" />
  </Target>
  
  <!-- 
  This task will do the CAT.Net analysis on the given assemblies
  -->

  <UsingTask AssemblyFile="C:\Program Files\MSBuild\MSBuildCommunityTasks\CATNETCustomTask.dll" TaskName="CATNETScan"/>
  <Target Name="CatNet" Condition="'$(EnableCatNet)'=='true'">  
    <Message Text=" "/>
    <Message Text="Testing CAT.NET Scan"/>
    <Message Text="------------------"/>
    <Message Text=" "/>
    <CATNETScan ScannedFiles="$(BuildDirectory)\Latest\$(ScanFiles)" CATNETPath="$(CNPath)" ReportLocation="$(BuildLogsDirectory)\Latest\$(CNRptFileName)" />
    <Copy DestinationFiles="$(BuildLogsDirectory)\$(BuildConfiguration)\$(BuildDateTime)\$(CNRptFileName)" SourceFiles="$(BuildLogsDirectory)\Latest\$(CNRptFileName)" ContinueOnError="true" />
  </Target>
  <!--
      This task will clean up all the files genera-
      ted by the previously ran 
      <SandcastleHelpFileBuilder> task.
  -->
  <Target Name="CleanUpSHFBFiles">
    <CreateItem Include="$(BuildLogsDirectory)\Latest\$(SandCastleOutputFolderName)\*.*" Condition=" '$(SandCastleOutputFolderName)' != '' ">
      <Output TaskParameter="Include" ItemName="OldSHFBFiles"/>
    </CreateItem>
    <Message Text="Files getting deleted are....@(OldSHFBFiles)" />
    <Delete Files="@(OldSHFBFiles)" ContinueOnError="true" Condition=" '@(OldSHFBFiles)' != '' " />
    <RemoveDir Directories="$(BuildLogsDirectory)\Latest\$(SandCastleOutputFolderName)" Condition=" '$(SandCastleOutputFolderName)' != '' " />
  </Target>


  <!--
      This task will create the msdn style help fi-
      les fo the assemblies built.
  -->
  <Target Name="SandcastleHelpFileBuilder">
    <Message Text="Executing....$(DOUBLE_QUOTES)$(SandCastleHFBExe)$(DOUBLE_QUOTES) $(DOUBLE_QUOTES)$(BuildSettingsDirectory)\$(SandCastleHFBProject)$(DOUBLE_QUOTES)" />
    <Exec Command="$(DOUBLE_QUOTES)$(SandCastleHFBExe)$(DOUBLE_QUOTES) $(DOUBLE_QUOTES)$(BuildSettingsDirectory)\$(SandCastleHFBProject)$(DOUBLE_QUOTES)" />
    <Exec Command="xcopy $(DOUBLE_QUOTES)$(BuildLogsDirectory)\Latest\$(SandCastleOutputFolderName)$(DOUBLE_QUOTES) $(DOUBLE_QUOTES)$(BuildLogsDirectory)\$(BuildConfiguration)\$(BuildDateTime)\$(SandCastleOutputFolderName)$(DOUBLE_QUOTES) /y /e /i"  ContinueOnError="true"/>
  </Target>


  <!--
      This task will clean up all the files genera-
      ted by the previously ran <NDepend> task.
  -->
  <Target Name="CleanNDependFiles">    
    <RemoveDir Directories="$(DOUBLE_QUOTES)$(BuildLogsDirectory)\Latest\$(NDependReportDirectory)$(DOUBLE_QUOTES)" Condition=" '$(NDependReportDirectory)' != '' " />
  </Target>


  <!--
      This task will anlyse the code for dependancies
      and report is generated which will help to 
      refactor and restructure the code.
  -->
  <Target Name="NDepend">
    <Exec Command="$(DOUBLE_QUOTES)$(NDependExe)$(DOUBLE_QUOTES) $(DOUBLE_QUOTES)$(BuildSettingsDirectory)\$(NDependProjectFile)$(DOUBLE_QUOTES)" />
    <Exec Command="xcopy $(DOUBLE_QUOTES)$(BuildLogsDirectory)\Latest\$(NDependReportDirectory)$(DOUBLE_QUOTES) $(DOUBLE_QUOTES)$(BuildLogsDirectory)\$(BuildConfiguration)\$(BuildDateTime)\$(NDependReportDirectory)$(DOUBLE_QUOTES) /y /e /i"  ContinueOnError="true" />
  </Target>


  <!--
      This task will create the database required 
      for the project by running a sql file.
  -->
  <Target Name="Create_db">
    <Message Text="Creating Database...."/>
    <Message Text="$(dbserver)"/>
    <Message Text="Executing...osql.exe -S $(dbserver) -U $(dbuser) -P $(dbpassword) -b -n -i $(CreateDbSqlFile)" />
    <Exec Command="$(DOUBLE_QUOTES)osql.exe$(DOUBLE_QUOTES) -S $(dbserver) -U $(dbuser) -P $(dbpassword) -b -n -i $(DOUBLE_QUOTES)$(CreateDbSqlFile)$(DOUBLE_QUOTES)" />
    <Message Text="Database Created successfully...."/>
  </Target>


  <!--
      This task will create tables in the database
      by running sql files specified.
  -->
  <Target Name="Create_tables" DependsOnTargets="Create_db">
    <Message Text="Creating Tables"/>
    <Message Text="Iterate for each item (for-each):  %(tablesqlfiles.Identity)"/>
    <Exec Command="$(DOUBLE_QUOTES)sqlcmd.exe$(DOUBLE_QUOTES) -S $(dbserver) -U $(dbuser) -P $(dbpassword) -i $(DOUBLE_QUOTES)%(tablesqlfiles.Identity)$(DOUBLE_QUOTES)"/>
  </Target>


  <!--
      This task will create views in the database
      by running sql files specified.
  -->
  <Target Name="Create_views" DependsOnTargets="Create_tables">
    <Message Text="Creating Views"/>
    <Exec Command="$(DOUBLE_QUOTES)sqlcmd.exe$(DOUBLE_QUOTES) -S $(dbserver) -U $(dbuser) -P $(dbpassword) -i $(DOUBLE_QUOTES)%(viewssqlfiles.Identity)$(DOUBLE_QUOTES)"/>
  </Target>


  <!--
      This task will create stored procedures in 
      the database by running sql files specified.
  -->
  <Target Name="Create_procs" DependsOnTargets="Create_views">
    <Message Text="Creating Stored procedures"/>
    <Exec Command="$(DOUBLE_QUOTES)sqlcmd.exe$(DOUBLE_QUOTES) -S $(dbserver) -U $(dbuser) -P $(dbpassword) -i $(DOUBLE_QUOTES)%(procssqlfiles.Identity)$(DOUBLE_QUOTES)"/>
  </Target>


  <!--
      This task will call all the database tasks
      in order.
  -->
  <Target Name="Database">
    <CallTarget Targets="Create_db" />
    <CallTarget Targets="Create_tables" />
    <CallTarget Targets="Create_views" />
    <CallTarget Targets="Create_procs" />
  </Target>


  <!--
      This task is the default target invoked if 
      no other specific targets are provided as 
      parameter to the msbuild command. Only a
      build complete message is printed here.
  -->
  <Target Name="Build" >
    <Message Text=" Build Complete"/>
  </Target>


    <!--
      This task will have all the steps to 
      be ran after the build script execution 
      is complete.
  -->
  <Target Name="PostScript">
    <Message Text="Excecuting PostScript Tasks........." />
    <Exec Command="$(BuildSettingsDirectory)\$(PostScriptFile)" />
  </Target>


  <Target Name="Mstest">
    <!--Exec Command="$(MStestExe) /testcontainer:$(MSTestDll) /resultsfile:$(MSTestOutPut)" /></Target-->
    <Exec Command="$(DOUBLE_QUOTES)$(MStestExe)$(DOUBLE_QUOTES) /testcontainer:$(BuildDirectory)\Latest\$(MSTestDll) /resultsfile:$(BuildLogsDirectory)\Latest\$(MSTestOutPut)" />
  </Target>

  <!--
      This task will have all the steps to 
      configure the IIS 
  -->

  <Target Name="IIS7Task" Condition="$(IISType)=='IIS 7.0'">
    <Message Text="Publishing the web project to stagging directory..." />
    <Exec Command="$(DOUBLE_QUOTES)C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe$(DOUBLE_QUOTES) -v /$(VdirName) -p $(DOUBLE_QUOTES)$(BuildSourceDirectory)\$(WebProjLocation)$(DOUBLE_QUOTES) $(VdirPhyPath) -f" />
    <Message Text="completed the deployment to stagging directory" />

    <Exec Command="$(DOUBLE_QUOTES)c:\Windows\System32\inetsrv\appcmd.exe$(DOUBLE_QUOTES) add app /site.name:$(DOUBLE_QUOTES)default web site$(DOUBLE_QUOTES) /path:/$(VdirName) /physicalPath:$(DOUBLE_QUOTES)$(VdirPhyPath)$(DOUBLE_QUOTES)"></Exec>
  </Target>

  <Target Name="IIS6Task" Condition="$(IISType)=='IIS 6.0'">

    <Message Text="Publishing the web project to stagging directory..." />
    <Exec Command="$(DOUBLE_QUOTES)C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe$(DOUBLE_QUOTES) -v /$(VdirName) -p $(DOUBLE_QUOTES)$(BuildSourceDirectory)\$(WebProjLocation)$(DOUBLE_QUOTES) $(VdirPhyPath) -f" />
    <Message Text="completed the deployment to stagging directory" />
    <!--<Message Text="Application Pool creation..." />
    <AppPoolCreate  ApplicationPoolName="$(AppPoolName)" />
    <Message Text="Application Pool created" />

    <Message Text="Virtual Directory Creation..." />
    <WebDirectoryCreate Server= "$(Server)"
          VirtualDirectoryName="$(VdirName)"
          VirtualDirectoryPhysicalPath="$(VdirPhyPath)" />
    <Message Text="Virtual Directory Creation completed" />

    <WebDirectorySetting
      ServerName="$(Server)"
      VirtualDirectoryName="$(VdirName)"
      SettingName="AppPoolId"
      SettingValue="$(AppPoolName)"
    />
    <Message Text="resetting the IIS server..." />-->
    <Exec Command="iisreset"></Exec>
    <Message Text="IIS restarted" />
  </Target>
  <Target Name="ProdDeploy" Condition="$(ProdDeployLoc) !=''">
    <Exec Command="$(DOUBLE_QUOTES)C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe$(DOUBLE_QUOTES) -v /$(VdirName) -p $(DOUBLE_QUOTES)$(BuildSourceDirectory)\$(WebProjLocation)$(DOUBLE_QUOTES) $(ProdDeployLoc) -f" />
  </Target>
  <Target Name="QADeploy" Condition="$(QADeployLoc) !=''">
    <Exec Command="$(DOUBLE_QUOTES)C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe$(DOUBLE_QUOTES) -v /$(VdirName) -p $(DOUBLE_QUOTES)$(BuildSourceDirectory)\$(WebProjLocation)$(DOUBLE_QUOTES) $(QADeployLoc) -f" />
  </Target>
  <Target Name="DevDeploy" Condition="$(DevDeployLoc) !=''">
    <Exec Command="$(DOUBLE_QUOTES)C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe$(DOUBLE_QUOTES) -v /$(VdirName) -p $(DOUBLE_QUOTES)$(BuildSourceDirectory)\$(WebProjLocation)$(DOUBLE_QUOTES) $(DevDeployLoc) -f" />
  </Target>
  
  <Target Name="PsExecTask" Condition="'$(EnableMOSSActivity)'=='true'">    
    <Exec Command="$(DOUBLE_QUOTES)$(PSexecPath)$(DOUBLE_QUOTES) $(MOSSServerName) /u:$(AdminUser) /p:$(DOUBLE_QUOTES)$(AdminPassword)$(DOUBLE_QUOTES) $(DOUBLE_QUOTES)$(ScriptStoreLoc)\Moss_Act_Controller.bat$(DOUBLE_QUOTES)" />
  </Target>
  <!--
      This task is the main task to be invoked 
      if all of the other targets has to be 
      executed at once in the dependancy order.
  -->

  <Target Name="WspCreationExe" Condition="'$(Wspexecs)' !=''">
    <ItemGroup>
      <TestExecs Include="$(Wspexecs)" />
    </ItemGroup>
    <Exec Command="%(TestExecs.Identity)" WorkingDirectory="%(TestExecs.rootdir)%(TestExecs.directory)"></Exec>
  </Target>

  <Target Name="ScimitarTask">
    <Exec Command="$(DOUBLE_QUOTES)$(BuildSettingsDirectory)\ScimitarPlugIn.exe$(DOUBLE_QUOTES) $(DOUBLE_QUOTES)$(TestXml)$(DOUBLE_QUOTES) $(DOUBLE_QUOTES)$(Sci_user)$(DOUBLE_QUOTES) $(DOUBLE_QUOTES)$(Sci_Password)$(DOUBLE_QUOTES) $(DOUBLE_QUOTES)$(Sci_MailList)$(DOUBLE_QUOTES) $(DOUBLE_QUOTES)$(Sci_WebRef)$(DOUBLE_QUOTES)" WorkingDirectory="$(BuildSettingsDirectory)"></Exec>
  </Target>

  <UsingTask TaskName="ConvertVSCoverageToXml" AssemblyFile="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\CI.MSBuild.Tasks.dll" />
  <Target Name="MSCodeCoverage" Condition ="'$(Instrbinaries)' !='' and '$(EnableMSCodeCoverage)'=='true'">    
    <ItemGroup>
      <Binaries Include="$(Instrbinaries)"></Binaries>
    </ItemGroup>
    <Message Text="%(Binaries.Identity)" />
    <Exec Command="$(DOUBLE_QUOTES)$(InstrExePath)$(DOUBLE_QUOTES) -coverage %(Binaries.Identity)" WorkingDirectory="$(BuildDirectory)\MSCodeCovDir"></Exec>
    <Exec Command="$(BuildDirectory)\MSCodeCovDir\mscodecov.bat" WorkingDirectory="$(BuildDirectory)\MSCodeCovDir"></Exec>    
    <ConvertVSCoverageToXml CoverageFiles="$(BuildDirectory)\MSCodeCovDir\$(outputCoverageFileName)"
                            SymbolsDirectory="$(BuildLogsDirectory)\Latest"
                            OutputDirectory="$(BuildLogsDirectory)\Latest" />    
  </Target>

  <Target Name="BuildAll">
    <CallTarget Targets="PreScript" Condition=" '$(EnablePreScriptTask)' == 'true' " />
    <CallTarget Targets="StartUp" />
    <CallTarget Targets="Version" Condition=" '$(EnableVersionTask)' == 'true' " />    
    <CallTarget Targets="CleanStyleCopFiles" />
    <CallTarget Targets="StyleCop" Condition=" '$(EnableStyleCopTask)' == 'true' " />
    <CallTarget Targets="Clean" />
    <CallTarget Targets="Compile" />
	  <CallTarget Targets="PostCompile" Condition="'$(EnablePostCompile)' == 'true'" />	
    <CallTarget Targets="Mstest" Condition=" '$(EnableMstestTask)' == 'true' " />    
    <CallTarget Targets="Database" Condition=" '$(EnableDatabaseTask)' == 'true' " />    
    <CallTarget Targets="CleanUpTestFiles" />
    <CallTarget Targets="UnitTest" Condition=" '$(EnableNUnitTask)' == 'true' " />
    <CallTarget Targets="CleanUpCoverageFiles" />
    <CallTarget Targets="Coverage" Condition=" '$(EnableNCoverTask)' == 'true' " />
    <CallTarget Targets="MSCodeCoverage"></CallTarget>    
    <CallTarget Targets="CleanUpFxcopFiles" />
    <CallTarget Targets="Reporting" Condition=" '$(EnableFxCopTask)' == 'true' " />
    <CallTarget Targets="CatNet" Condition="'$(EnableCatNet)'=='true'" />    
    <CallTarget Targets="CleanUpSHFBFiles" />
    <CallTarget Targets="SandcastleHelpFileBuilder" Condition=" '$(EnableSandCastleHFBTask)' == 'true' " />
    <CallTarget Targets="CleanNDependFiles" />
    <CallTarget Targets="NDepend" Condition=" '$(EnableNDependTask)' == 'true' " />    
    <CallTarget Targets="IIS6Task" Condition=" '$(IISType)' == 'IIS 6.0' and '$(EnableIIS)' == 'true'" />
    <CallTarget Targets="IIS7Task" Condition=" '$(IISType)' == 'IIS 7.0' and '$(EnableIIS)' == 'true'" />
    <CallTarget Targets="PostDeploy" Condition="'$(EnablePostDeploy)' == 'true'" />
    <CallTarget Targets="ProdDeploy" />
    <CallTarget Targets="QADeploy" />
    <CallTarget Targets="DevDeploy" />
    <CallTarget Targets="ScimitarTask" Condition="'$(EnableScimitar)'=='true'" />
    <CallTarget Targets="PostScript" Condition=" '$(EnablePostScriptTask)' == 'true' " />    
    <CallTarget Targets="WspCreationExe" />
    <CallTarget Targets="PsExecTask" />
  </Target>
</TargetsRoot>
